package com.tpp.base.controller;

import com.tpp.base.service.AdminCinemaService;
import com.tpp.comm.pojo.TpCinema;
import com.tpp.comm.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/s/cinema")
public class AdminCinemaController {

    @Resource
    private AdminCinemaService adminCinemaService;
    

    @GetMapping("/findCinema")
    public Result findCinema(){
        return Result.success(adminCinemaService.findCinema());
    }

    @PostMapping("/add")
    public Result addCinema(@RequestBody TpCinema tpCinema){
        try {
            adminCinemaService.addCinema(tpCinema);
            return Result.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("添加失败");
        }
    }

    @PostMapping("/update")
    public Result updateCinema(@RequestBody TpCinema tpCinema){
        try {
            adminCinemaService.updateCinema(tpCinema);
            return Result.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("修改失败");
        }
    }

    @GetMapping("/delete")
    public Result deleteCinema(Integer id){
        try {
            adminCinemaService.deleteCinema(id);
            return Result.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.fail("删除失败");
        }
    }

    @GetMapping("/findById")
    public Result findById(Integer id){
        return Result.success(adminCinemaService.findById(id));
    }

    @GetMapping("/findByAreaId")
    public Result findByAreaId(Integer areaId){
        return Result.success(adminCinemaService.findByAreaId(areaId));
    }
    
}
